package com.woniuxy.controller;

import com.woniuxy.entity.MyDataSource;
import com.woniuxy.entity.MyPropertiesDataSource;
import com.woniuxy.entity.RbacManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Date;

@Controller
public class MySpringBootController {
    @Value("${server.port}")
    String port;
    @Value("${spring.application.name}")
    String appname;
    @Autowired
    MyDataSource myDataSource;
    @Autowired
    MyPropertiesDataSource myPropertiesDataSource;

    @RequestMapping("/index")
    public String index(Model model) {
        System.out.println(myDataSource.toString());
        System.out.println("当前服务的端口:"+port);
        System.out.println("当前服务的名称:"+appname);
        System.out.println("从properties中获取的数据："+myPropertiesDataSource);
        model.addAttribute("port",port);
        return "index";
    }
    @RequestMapping("/testDate")
    @ResponseBody
    public String testDate(@RequestParam Date times){
        return times.toString();
    }

    @RequestMapping("/testJsonDate")
    @ResponseBody
    public String testJsonDate(@RequestBody RbacManager rbacManager){

        return rbacManager.getTimes().toString();
    }
    @RequestMapping("/testJsonDate15")
    @ResponseBody
    public String testJsonDate1(@RequestBody RbacManager rbacManager){

        return rbacManager.getTimes().toString();
    }
}
